package com.example.administrator.waitan.find.news;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.base.BaseActivity;
import com.example.administrator.waitan.find.news.newscontent.NewsContentActivity;
import com.example.administrator.waitan.tools.GsonRequest;
import com.example.administrator.waitan.tools.VolleySingleton;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/18.
 */
public class NewsActivity extends BaseActivity {
    private NewsBaseAdapter mAdapter;
    private ListView mListView;
    private RequestQueue queue;
    private NewsData datas;
    private List<NewsComics> comicses;
    private List<NewsTopic> topics;
    private List<NewsUser> users;
    private String url = "http://api.alithefox.net/comic_lists/1?limit=20&offset=0";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final NewsProgressDialog dialog = new NewsProgressDialog(this,"世界那么大...",R.anim.activity_in);
        dialog.show();
        setContentView(R.layout.activity_news);
        mListView = (ListView) findViewById(R.id.lv_news);
        GsonRequest<NewsBeans> newsBeansGsonRequest = new GsonRequest<NewsBeans>(url, NewsBeans.class, new Response.Listener<NewsBeans>() {
            @Override
            public void onResponse(final NewsBeans response) {
                mAdapter = new NewsBaseAdapter(response.getData().getComics(),NewsActivity.this);
                Log.d("com",response.getData().getComics().size() + "");
                mListView.setAdapter(mAdapter);
                dialog.dismiss();
                mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        Intent goNewsContent = new Intent(NewsActivity.this,NewsContentActivity.class);
                        goNewsContent.putExtra("Id",response.getData().getComics().get(i).getComic_id());
                        startActivity(goNewsContent);
                    }
                });
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        VolleySingleton.getInstance()._addRequest(newsBeansGsonRequest);
    }
}
